package com.crm.service.impl.internalTrainingManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.internalTrainingManager.NxContactMapper;
import com.crm.model.entity.internalTrainingManager.NxContact;
import com.crm.model.entity.internalTrainingManager.NxContactExample;
import com.crm.model.qo.internalTrainingManager.NxContactQO;
import com.crm.service.internalTrainingManager.NxContactDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 内训部领取客户
 * @Author renshaorong
 * @Date 2021/9/6
 */
@Service
public class NxContactDbServiceImpl implements NxContactDbService {

    @Autowired
    NxContactMapper nxContactMapper;

    @Override
    public List<NxContact> selectByCustomerId (NxContactQO nxContactQO){
        NxContactExample nxContactExample = new NxContactExample();
        NxContactExample.Criteria criteria = nxContactExample.createCriteria();
        criteria.andCustomerIdEqualTo(nxContactQO.getCustomerId());
        criteria.andDeleteStatusEqualTo((short)0);
        return nxContactMapper.selectByExample(nxContactExample);
    }

    @Override
    public boolean insertNxContact(NxContact nxContact) {
        return nxContactMapper.insertSelective(nxContact)>0;
    }

    @Override
    public List<NxContact> selectNxContactByCustomerId(String customerId) {
        NxContactExample nxContactExample = new NxContactExample();
        nxContactExample.setOrderByClause("create_tm desc");
        NxContactExample.Criteria criteria = nxContactExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        return nxContactMapper.selectByExample(nxContactExample);
    }

    @Override
    public NxContact selectNxContactByContactInformation(String contactInformation,String customerId) {
        NxContactExample nxContactExample = new NxContactExample();
        NxContactExample.Criteria criteria = nxContactExample.createCriteria();
        criteria.andContactInformationEqualTo(contactInformation);
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<NxContact> nxContacts = nxContactMapper.selectByExample(nxContactExample);
        return nxContacts.size() > 0 ? nxContacts.get(0) : null;
    }

}